<?php echo $header; ?>
<?php echo $column_left; ?>
<div id="content">
	<div class="page-header">
    	<div class="container-fluid">
        	<div class="pull-right">
            	<button type="submit" id="btn_save" form="form-product" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="Save"><i class="fa fa-save"></i></button>
                <a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="Cancel"><i class="fa fa-reply"></i></a>
            </div>
            <h1> <?php echo $heading_title; ?> </h1>
            <ul class="breadcrumb">
            	<?php foreach ($breadcrumbs as $breadcrumb) { ?>
					<li> <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
    			<?php } ?>
            </ul>
        </div>
    </div>
    <div class="container-fluid">
     	<?php if ($error_warning) { ?>
            <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
              <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
        <?php } ?>
    	<div class="panel panel-default">
        	<div class="panel-heading">
            	<h3 class="panel-title"><i class="fa fa-pencil"></i><?php echo $heading_title; ?></h3>
            </div>
            <div class="panel-body">            
            	<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form" class="form-horizontal">
                	<ul class="nav nav-tabs">
                    	<li class="active"> <a href="#tab-general" data-toggle="tab"><?php echo $tab_general; ?></a></li>
                        <li> <a href="#tab-links" data-toggle="tab"><?php echo $tab_links; ?></a></li>
                        <li> <a href="#tab-design" data-toggle="tab"><?php echo $tab_design; ?></a> </li>
                    </ul>
                    <div class="tab-content">
                    	<div class="tab-pane active" id="tab-general">
                        	<ul class="nav nav-tabs" id='language'>
                            	 <?php $i=0; foreach ($languages as $language) {$i++; ?>
            						<li <?php echo ($i ==1)?"class='active'":""?>> <a href="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a></li>
            					<?php } ?>
                            </ul>
                            <?php $lang=0; foreach ($languages as $language) {$lang++; ?>
                            <div class="tab-content" >
                            	<div class="tab-pane <?php echo ($lang==1)?"active":""?>" id="language<?php echo $language['language_id']; ?>">
                                    <div class="form-group required">
                                        <label class="col-sm-2 control-label"><?php echo $entry_name; ?></label>
                                        <div class="col-sm-10">
                                               <input type="text" name="blogs_description[<?php echo $language['language_id']; ?>][name]" id="blogs_description_<?php echo $language['language_id']; ?>_name" onkeyup="trim_name(this.id);" size="100" value="<?php echo isset($blogs_description[$language['language_id']]) ? $blogs_description[$language['language_id']]['name'] : ''; ?>" class="form-control" />
                                              <?php if (isset($error_name[$language['language_id']])) { ?>
                                              <span class="error"><?php echo $error_name[$language['language_id']]; ?></span>
                                              <?php } ?>
                                        </div>
                                        <div class="clear"></div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $entry_short_description; ?></label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control" name="blogs_description[<?php echo $language['language_id']; ?>][short_description]" cols="97" rows="5"><?php echo isset($blogs_description[$language['language_id']]) ? $blogs_description[$language['language_id']]['short_description'] : ''; ?></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                    	<label class="col-sm-2 control-label"><?php echo $entry_description; ?></label>
                                        <div class="col-sm-10"><textarea  class="form-control" name="blogs_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($blogs_description[$language['language_id']]) ? $blogs_description[$language['language_id']]['description'] : ''; ?></textarea></div>
                                    </div>
									<div class="form-group">
                                    	<label class="col-sm-2 control-label"><?php echo $entry_tag; ?></label>
                                        <div class="col-sm-10"><input type="text" name="blogs_tag[<?php echo $language['language_id']; ?>]" value="<?php echo isset($blogs_tag[$language['language_id']]) ? $blogs_tag[$language['language_id']] : ''; ?>" size="80" class="form-control" /></div>
                                    </div>
                                    <div class="form-group">
                                    	<label class="col-sm-2 control-label"><?php echo $entry_meta_keyword; ?></label>
                                        <div class="col-sm-10"><textarea class="form-control" name="blogs_description[<?php echo $language['language_id']; ?>][meta_keyword]" cols="40" rows="5"><?php echo isset($blogs_description[$language['language_id']]) ? $blogs_description[$language['language_id']]['meta_keyword'] : ''; ?></textarea></div>
                                    </div>
                                    <div class="form-group">
                                    	<label class="col-sm-2 control-label"><?php echo $entry_meta_description; ?></label>
                                        <div class="col-sm-10"><textarea class="form-control" rows="5" name="blogs_description[<?php echo $language['language_id']; ?>][meta_description]" cols="40" rows="5"><?php echo isset($blogs_description[$language['language_id']]) ? $blogs_description[$language['language_id']]['meta_description'] : ''; ?></textarea></div>
                                    </div>
								</div>
                            </div><!-- tab-content -->
                            <?php }?>
                        </div><!-- tab-general -->
                        <div class="tab-pane" id="tab-links">
                        	<style>.input-checkbox{border:1px solid #CECECE;background:#F0F0F0;padding:10px;height: 120px;width: 320px;overflow-y:scroll}.input-checkbox input{margin-left:20px;margin-right:10px;}</style>
                        	<div class="form-group required">
                            	<label class="col-sm-2 control-label"> <?php echo $entry_category; ?> </label>
                                <div class="col-sm-9">
                            		<?php $class = 'odd'; ?>
                                    <div class="input-checkbox">
                                        <?php foreach ($categories as $category) { ?>
                                        <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                                        <?php if (in_array($category['blogs_category_id'], $blogs_category)) { ?>
                                             <input type="checkbox" name="blogs_category[]" value="<?php echo $category['blogs_category_id']; ?>" checked="checked" /><?php echo $category['name']; ?><br />
                                        <?php }else{?>
                                              <input type="checkbox" name="blogs_category[]" value="<?php echo $category['blogs_category_id']; ?>" /><?php echo $category['name']; ?><br />
                                        <?php }}?>
                                    </div>
                                </div>
                            </div><!-- form-group -->
                            <div class="form-group required">
                            	<label class="col-sm-2 control-label"> <?php echo $entry_store; ?> </label>
                                <div class="col-sm-9">
                                    <div class="input-checkbox">
                                        <?php if (in_array(0, $blogs_store)) { ?>
                                        <input type="checkbox" name="blogs_store[]" value="0" checked="checked" />
                                        <?php echo $text_default; ?><br />
                                        <?php } else { ?>
                                        <input type="checkbox" name="blogs_store[]" value="0" />
                                        <?php echo $text_default; ?><br />
                                        <?php } ?>
                                        <?php foreach ($stores as $store) { ?>
                                         	<div class="<?php echo $class; ?>">
                                            <?php if (in_array($store['store_id'], $blogs_store)) { ?>
                                            <input type="checkbox" name="blogs_store[]" value="<?php echo $store['store_id']; ?>" checked="checked" />
                                            <?php echo $store['name']; ?><Br />
                                            <?php } else { ?>
                                            <input type="checkbox" name="blogs_store[]" value="<?php echo $store['store_id']; ?>" />
                                            <?php echo $store['name']; ?><Br />
                                            <?php } ?>
                                        <?php }?>
                                    </div>
                                </div><!-- col-sm-9 -->
                            </div><!-- form-group -->
							<div class="form-group required">
                            	<label class="col-sm-2 control-label"> <?php echo $entry_keyword; ?> </label>
                                <div class="col-sm-9">
                                	<input type="text" class="form-control" name="keyword" id="seo_keyword" value="<?php echo $keyword; ?>" />
                                </div><!-- col-sm-9 -->
                            </div><!-- form-group -->
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="input-image"><?php echo $entry_image; ?></label>
                                <div class="col-sm-10">
                                  <a href="" id="thumb-image" data-toggle="image" class="img-thumbnail"><img src="<?php echo $thumb; ?>" alt="" title=""  /></a>
                                  <input type="hidden" name="image" value="<?php echo $image; ?>" id="input-image" />
                                </div>
                            </div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label"> <?php echo $entry_date_available; ?> </label>
                                <div class="col-sm-9">
                               		<input type="text" name="date_available" value="" placeholder="Date Start" data-format="YYYY-MM-DD" class="form-control">
                 					<!--<input type="text" name="date_available" value="<?php echo $date_available; ?>" size="12" class="form-control date"/>-->
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
                             <div class="form-group">
                            	<label class="col-sm-2 control-label"> <?php echo $entry_related; ?></label>
                                <div class="col-sm-9">
                                    <input type="text" name="related" value="" size="12" class="form-control "/>
                                    <div class="well well-sm scrollbox" id="blogs-related"  style="height: 150px; overflow: auto;">
                                        <?php $class = 'odd'; ?>
                                        <?php foreach ($blogs_related as $blogs_related) { ?>
                                        <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                                        <div id="blogs-related<?php echo $blogs_related['blogs_id']; ?>" class="<?php echo $class; ?>"> <i class="fa fa-minus-circle"></i> <?php echo $blogs_related['name']; ?>
                                        <input type="hidden" name="blogs_related[]" value="<?php echo $blogs_related['blogs_id']; ?>" />
                                        </div>
                                        <?php } ?>
                                    </div><!-- scrollbox -->
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
							 <div class="form-group">
                            	<label class="col-sm-2 control-label"><?php echo $entry_comment; ?></label>
                                <div class="col-sm-9">
                 					<select name="comment">
                                      <?php if ($comment) { ?>
                                      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                                      <option value="0"><?php echo $text_disabled; ?></option>
                                      <?php } else { ?>
                                      <option value="1"><?php echo $text_enabled; ?></option>
                                      <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                                      <?php } ?>
                                    </select>
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
							 <div class="form-group">
                            	<label class="col-sm-2 control-label"><?php echo $entry_approved; ?></label>
                                <div class="col-sm-9">
                 					<select name="approved">
                                      <?php if ($approved) { ?>
                                      <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                                      <option value="0"><?php echo $text_no; ?></option>
                                      <?php } else { ?>
                                      <option value="1"><?php echo $text_yes; ?></option>
                                      <option value="0" selected="selected"><?php echo $text_no; ?></option>
                                      <?php } ?>
                                    </select>
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
                             <div class="form-group">
                            	<label class="col-sm-2 control-label"><?php echo $entry_status; ?></label>
                                <div class="col-sm-9">
                 					<select name="status">
                                      <?php if ($status) { ?>
                                      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                                      <option value="0"><?php echo $text_disabled; ?></option>
                                      <?php } else { ?>
                                      <option value="1"><?php echo $text_enabled; ?></option>
                                      <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                                      <?php } ?>
                                    </select>
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
							 <div class="form-group">
                            	<label class="col-sm-2 control-label"><?php echo $entry_sort_order; ?></label>
                                <div class="col-sm-9">
                 					<input type="text" name="sort_order" value="<?php echo $sort_order; ?>" size="2" />
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
                        </div>  
                        <div class="tab-pane"  id="tab-design">
                        	 <div class="form-group">
                            	<label class="col-sm-2 control-label"><?php echo $text_default; ?></label>
                                <div class="col-sm-9">
                 					<select name="blogs_layout[0][layout_id]">
                                        <option value=""></option>
                                        <?php foreach ($layouts as $layout) { ?>
                                        <?php if (isset($blogs_layout[0]) && $blogs_layout[0] == $layout['layout_id']) { ?>
                                        <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                                        <?php } else { ?>
                                        <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                                        <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div><!-- col-sm-9 -->
                             </div><!-- form-group -->
                             <?php foreach ($stores as $store) { ?>
                             	<div class="form-group">
                                	<label class="col-sm-2 control-label"><?php echo $store['name']; ?></label>
                                    <div class="col-sm-9">
                                    	<select name="blogs_layout[<?php echo $store['store_id']; ?>][layout_id]">
                                            <option value=""></option>
                                            <?php foreach ($layouts as $layout) { ?>
                                            <?php if (isset($blogs_layout[$store['store_id']]) && $blogs_layout[$store['store_id']] == $layout['layout_id']) { ?>
                                            <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                                            <?php } else { ?>
                                            <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                                            <?php } ?>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                             <?php }?>
                        </div>                    
                    </div>
      			</form>
            </div>
        </div>
    </div>
</div>
</script> 
<script type="text/javascript">
$('input[name=\'related\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=catalog/blogs/autocomplete&token=<?php echo $token; ?>',
			type: 'POST',
			dataType: 'json',
			data: 'filter_name=' +  encodeURIComponent($('input[name=\'related\']').val()),
			success: function(data) {		
				response($.map(data, function(item) {
					return {
						label: item.name,
						value: item.blogs_id
					}
				}));
			}
		});
	}, 
	select: function(item) {
		$('#blogs-related' + item['value']).remove();
		$('#blogs-related').append('<div id="blogs-related' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="blogs_related[]" value="' + item['value'] + '" /></div>');
		$('#blogs-related div:odd').attr('class','odd');
		$('#blogs-related div:even').attr('class','even');
		$('#blogs-related .fa-minus-circle').off("click");	
		$('#blogs-related .fa-minus-circle').click(function() {
			$(this).parent().remove();
			$('#blogs-related div:odd').attr('class', 'odd');
			$('#blogs-related div:even').attr('class', 'even');	
		});

		return false;
	}
});
$('#blogs-related .fa-minus-circle').click(function() {
	$(this).parent().remove();
	$('#blogs-related div:odd').attr('class', 'odd');
	$('#blogs-related div:even').attr('class', 'even');	
});
$('input[name="date_available"]').datetimepicker();
$("#btn_save").click(function(){$("#form").submit();});
$('#description1').summernote({height: 300});
/*$('#blogs-related div img').live('click', function() {
	$(this).parent().remove();
	
	$('#blogs-related div:odd').attr('class', 'odd');
	$('#blogs-related div:even').attr('class', 'even');	
});*/
</script> 
<script type="text/javascript">
/*$.widget('custom.catcomplete', $.ui.autocomplete, {
	_renderMenu: function(ul, items) {
		var self = this, currentCategory = '';
		
		$.each(items, function(index, item) {
			if (item.category != currentCategory) {
				ul.append('<li class="ui-autocomplete-category">' + item.category + '</li>');
				
				currentCategory = item.category;
			}
			
			self._renderItem(ul, item);
		});
	}
});*/

</script> 
<?php echo $footer; ?>